package org.example.utils;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true) // chain 属性不写默认为false，当该值为 true 时，对应字段的 setter 方法调用后，会返回当前对象。
public class ResultData<T> {
    private String code ; //结果状态，具体状态码参见枚举类ReturnCodeEnum
    private String message; // 状态描述
    private T data; //返回的数据
    private long timestamp; //时间戳


    private ResultData(){
        this.timestamp = System.currentTimeMillis();
    }


    //成功
    public static <T> ResultData<T> success(T data){
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCodeEnum.RC00.getCode());
        resultData.setMessage(ReturnCodeEnum.RC00.getMessage());
        resultData.setData(data);
        return  resultData;
    }


    //失败
    public static <T> ResultData<T> fail(String code, String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }







}
